package com.example.springbootlearning.controller;

//import org.springframework.web.bind.annotation.RequestMapping;
import com.example.springbootlearning.base.BizException;
import com.example.springbootlearning.base.Result;
import com.example.springbootlearning.service.UserService;
import com.example.springbootlearning.vo.User;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController // 相当于@ResponseBody和@Controller的结合
public class FirstController {

    @Resource
    private UserService userService;

    @Value("${custom.chicken.word}")
    private String word;

    @RequestMapping("sayHello")
    public String sayHello() {
        System.out.println("🏀🏀🏀");
        return word;
    }

    @GetMapping("/getWord")
    public String getWord() {
        return "这是get方法";
    }

    @GetMapping("/getUserByGet")
    public User getUserByGet(User user) {
        return user;
    }

    @PostMapping("/getUserByPost")
    public User getUserByPost(@RequestBody User user) {
        return user;
    }
    @GetMapping("/throwError")
    public void throwError(){
        int a = 10/0;
    }

    @GetMapping("/throwBizExpection")
    public boolean throwBizExpection() {
        throw new BizException();
    }

    @PostMapping("/getUserById")
    public Result<User> getUserById(@RequestBody int id) {
        User userVO = userService.getUserById(id);
        System.out.println(userVO);
        return Result.success(userVO);
    }


}
